﻿//========================================
// All rights reserved (C) 2017-2100
// CLR 版本：	4.0.30319.42000
// 命名空间:	SFJDService.TransportHandle
// 文 件 名：	FileByteIndex
// 作    者：	WooG
// 联系方式：	wooglle@163.com
// 创建时间：	2018/6/26 8:33:29
//========================================
using System;

namespace SFJDService.TransportHandle
{
    public struct FileByteIndex : IEquatable<FileByteIndex>
    {
        public int FileIndex { set; get; }
        public int ByteIndex { set; get; }

        public FileByteIndex(PacketFileTransport packet)
        {
            FileIndex = packet.FileIndex;
            ByteIndex = packet.ByteIndex;
        }

        public FileByteIndex(PacketFileCheck check)
        {
            FileIndex = check.FileIndex;
            ByteIndex = check.ByteIndex;
        }

        public override bool Equals(object obj)
        {
            if (!(obj is FileByteIndex))
            {
                return false;
            }

            var index = (FileByteIndex)obj;
            return FileIndex == index.FileIndex &&
                   ByteIndex == index.ByteIndex;
        }

        public bool Equals(FileByteIndex other)
        {
            return FileIndex == other.FileIndex &&
                   ByteIndex == other.ByteIndex;
        }

        public override int GetHashCode()
        {
            var hashCode = -1017083706;
            hashCode = hashCode * -1521134295 + base.GetHashCode();
            hashCode = hashCode * -1521134295 + FileIndex.GetHashCode();
            hashCode = hashCode * -1521134295 + ByteIndex.GetHashCode();
            return hashCode;
        }

        public override string ToString()
        {
            return ByteIndex + "/" + FileIndex;
        }

        public static bool operator ==(FileByteIndex index1, FileByteIndex index2)
        {
            return index1.Equals(index2);
        }

        public static bool operator !=(FileByteIndex index1, FileByteIndex index2)
        {
            return !(index1 == index2);
        }
    }
}